import { loginApi } from '@/api/user.js'// userApi
import { getToken, setToken, delToken } from '@/utils/storage'

export default {
  state () {
    return {
      token: getToken()
    }
  },
  mutations: {
    // 获取token,并且存储到本地
    changeToken (state, token) {
      state.token = token
      setToken(token)
    },
    // 清除token
    removeToken (state) {
      state.token = null
      delToken()
    },
    // 更新菜单数据
    setMenuList (state, arr) {
      state.menuList = arr
    }

  },
  actions: {
    // 用户登陆
    async login ({ commit }, data) {
      const res = await loginApi(data)
      commit('changeToken', res.data.token)
      console.log(res)
    },
    // 退出登陆
    async loginOut ({ commit }, data) {
      commit('removeToken')
    }
    // 获取侧边导航栏
    // async menus ({ commit }) {
    //   const res = await menusApi()
    //   commit('setMenuList')
    //   console.log(res.data, 8888);
    // }

  },
  getters: {},
  namespaced: true
}
